< previous page page_199 next page >

Page 199
InStr( )
InStr() returns the location where one string resides in another string. String functions are one based, not zero based like arrays. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdInstr_Click ()
   Dim strName As String
   strName = "Bill Gates"

   Me.Cls
   Me.Print strName
   Me.Print InStr(strName, "G")
   Me.Print InStr(strName, "Gates")
End Sub
The first argument you typically pass to the Instr() function is the string you wish to search within. The next parameter is the string you wish to search for. This function will return the numeric location of where the 2nd parameter is located within the first.
InStrRev( )
InStrRev() returns the location where one string resides in another string, but from the end of the string. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdInstrRev_Click()
   Dim strValue As String

   strValue = "Microsoft Visual Basic 6.0"
   Me.Cls
   Me.Print "strValue = " & strValue
   Me.Print "InStr(strValue, ""B"") = " & InStr(strValue, "B")
   Me.Print "InStr(strValue, ""Visual"") = " & _
            InStr(strValue, "Visual")
End Sub
Left$( )
Left$() returns the leftmost number of characters specified in a string. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdLeft_Click ()
   Dim strName As String
   strName = "Bill Gates"

 
< previous page page_199 next page >

If you like this book, buy it!